package com.newedu.equipmgr.service;

import com.newedu.equipmgr.dao.AreaDao;
import com.newedu.equipmgr.dao.AreaDaoImpl;
import com.newedu.equipmgr.entity.AreaInfo;

import java.util.List;

/**
 * @author jerry
 * @create 2020-06-08 10:22:00
 * @company 新开普电子股份有限公司
 */
public class AreaService {
    private AreaDao areaDao = new AreaDaoImpl();

    public boolean insert(AreaInfo areaInfo) throws RuntimeException{
        boolean result = false;
        try{
            result = areaDao.insert(areaInfo);
        }
        catch (Exception e){
            // 从编译时异常，转换为运行时异常
            throw new RuntimeException(e);
        }
        return result;
    }
    public boolean update(AreaInfo areaInfo) throws RuntimeException{
        boolean result = false;
        try{
            result = areaDao.update(areaInfo);
        }
        catch (Exception e){
            // 从编译时异常，转换为运行时异常
            throw new RuntimeException(e);
        }
        return result;
    }
    public boolean delete(int id) throws RuntimeException{
        boolean result = false;
        try{
            result = areaDao.delete(id);
        }
        catch (Exception e){
            // 从编译时异常，转换为运行时异常
            throw new RuntimeException(e);
        }
        return result;
    }
    public AreaInfo selectOne(int id) throws RuntimeException{
        AreaInfo areaInfo = null;
        try{
            areaInfo = areaDao.selectOne(id);
        }
        catch (Exception e){
            // 从编译时异常，转换为运行时异常
            throw new RuntimeException(e);
        }
        return areaInfo;
    }
    public List<AreaInfo> selectAll() throws RuntimeException{
        List<AreaInfo> areaInfoList = null;
        try{
            areaInfoList = areaDao.selectAll();
        }
        catch (Exception e){
            // 从编译时异常，转换为运行时异常
            throw new RuntimeException(e);
        }
        return areaInfoList;
    }
    public List<AreaInfo> selectBy(String condition, int pageNum, int pageSize) throws RuntimeException{
        List<AreaInfo> areaInfoList = null;
        try{
            areaInfoList = areaDao.selectBy(condition,pageNum,pageSize);
        }
        catch (Exception e){
            // 从编译时异常，转换为运行时异常
            throw new RuntimeException(e);
        }
        return areaInfoList;
    }
    public int countRows(String condition) throws RuntimeException{
        int rows =0;
        try{
            rows = areaDao.countRows(condition);
        }
        catch (Exception e){
            // 从编译时异常，转换为运行时异常
            throw new RuntimeException(e);
        }
        return rows;
    }

    public List<AreaInfo>  selectAreaInfoBy(String condition){
        List<AreaInfo> areaInfoList = null;
        try{
            areaInfoList = areaDao.selectAreaInfoBy(condition);
        }
        catch (Exception e){
            throw new RuntimeException("区域信息查询失败！");
        }
        return areaInfoList;
    }
}
